package com.kpx.app.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kpx.app.R;
import com.kpx.app.bean.TagBean;

/**
 * Created by Administrator on 2017/4/11.
 */

public class TagView extends LinearLayout {

    private final View view;
    private final Context context;
    private TagBean.ChildTagsBean s;
    private final TextView t;

    public TagView(Context context) {
        super(context);
        this.context = context;
        view = View.inflate(context, R.layout.tag_view, this);
        t = (TextView) view.findViewById(R.id.txt);
    }

    public void setData(TagBean.ChildTagsBean s) {
        this.s = s;
        t.setText(s.getTagName());
        refresh();
    }

    public TagBean.ChildTagsBean back() {
        return s;
    }

    public void refresh() {
        if (s.isSelect()) {
            Drawable drawable = getResources().getDrawable(R.drawable.sign_select);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            t.setCompoundDrawablePadding(5);
            t.setCompoundDrawables(null, null, drawable, null);
        } else {
            t.setCompoundDrawables(null, null, null, null);
        }
        t.setBackgroundResource(s.isSelect() ? R.drawable.tag_grey_shape : R.drawable.tag_white_shape);
    }

    public void setTopon() {
        Drawable drawable = getResources().getDrawable(R.drawable.sign_selected);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        t.setCompoundDrawables(null, null, drawable, null);
        t.setCompoundDrawablePadding(5);
        t.setTextColor(context.getResources().getColor(R.color.white));
        t.setBackgroundResource(R.drawable.tag_red_shape);
    }
}
